﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Serialization;
using System.Drawing;

namespace TeenyGrab.Serialization
{
    [Serializable]
    public class SerializableScreen : ISerializable
    {
        public Screen Screen { get; set; }

        public SerializableScreen(SerializationInfo info, StreamingContext context)
        {
            var parts = info.GetString("Screen").Split(new char[] { 'x' });
            if (parts.Length == 2)
            {
                Screen = Screen.FromPoint(new Point(Int32.Parse(parts[0]+1), Int32.Parse(parts[1]+1)));
            }
            else
            {
                Screen = null;
            }
        }

        public SerializableScreen()
        {
            Screen = Screen.PrimaryScreen;
        }

        public SerializableScreen(Screen screen)
        {
            Screen = screen;
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            if (Screen == null)
                info.AddValue("Screen", "null");
            else
                info.AddValue("Screen", Screen.Bounds.Location.X + "x" + Screen.Bounds.Location.Y);
        }
    }
}
